home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / workbench / directoryopus4 / dopus4_src / program / searchdata.c < prev    next >
C/C++ Source or Header  |  2000-03-11  |  9KB  |  269 lines

  1. /*
  2.  
  3. Directory Opus 4
  4. Original GPL release version 4.12
  5. Copyright 1993-2000 Jonathan Potter
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. All users of Directory Opus 4 (including versions distributed
  22. under the GPL) are entitled to upgrade to the latest version of
  23. Directory Opus version 5 at a reduced price. Please see
  24. http://www.gpsoft.com.au for more information.
  25.  
  26. The release of Directory Opus 4 under the GPL in NO WAY affects
  27. the existing commercial status of Directory Opus 5.
  28.  
  29. */
  30.  
  31. #include "dopus.h"
  32. #include "searchdata.h"
  33.  
  34. enum {
  35.     SEARCH_TEXT,
  36.     SEARCH_CASE,
  37.     SEARCH_WILD,
  38.     SEARCH_ONLYWORD,
  39.     SEARCH_OKAY,
  40.     SEARCH_CANCEL};
  41.  
  42. struct TagItem
  43.     search_title[]={
  44.         {RO_Type,OBJECT_BORDER},
  45.         {RO_BorderType,BORDER_NONE},
  46.         {RO_LeftFine,4},
  47.         {RO_Width,38},
  48.         {RO_WidthFine,32},
  49.         {RO_TopFine,-4},
  50.         {RO_Height,1},
  51.         {RO_TextPos,TEXTPOS_CENTER},
  52.         {RO_TextNum,STR_ENTER_SEARCH_STRING},
  53.         {TAG_END,0}},
  54.  
  55.     search_text_gadget[]={
  56.         {RO_Type,OBJECT_GADGET},
  57.         {RO_GadgetType,GADGET_STRING},
  58.         {RO_GadgetID,SEARCH_TEXT},
  59.         {RO_Top,1},
  60.         {RO_LeftFine,4},
  61.         {RO_Width,38},
  62.         {RO_WidthFine,32},
  63.         {RO_Height,1},
  64.         {RO_StringLen,80},
  65.         {RO_StringBuf,0},
  66.         {RO_StringUndo,(ULONG)str_undobuffer},
  67.         {TAG_END,0}},
  68.  
  69.     search_case_gadget[]={
  70.         {RO_Type,OBJECT_GADGET},
  71.         {RO_GadgetType,GADGET_CHECK},
  72.         {RO_GadgetID,SEARCH_CASE},
  73.         {RO_Top,2},
  74.         {RO_TopFine,6},
  75.         {RO_TextNum,STR_SEARCH_NO_CASE},
  76.         {RO_TextPos,TEXTPOS_RIGHT},
  77.         {RO_ChkCenter,TRUE},
  78.         {RO_BoolOn,FALSE},
  79.         {TAG_END,0}},
  80.     search_wild_gadget[]={
  81.         {RO_Type,OBJECT_GADGET},
  82.         {RO_GadgetType,GADGET_CHECK},
  83.         {RO_GadgetID,SEARCH_WILD},
  84.         {RO_Top,3},
  85.         {RO_TopFine,11},
  86.         {RO_TextNum,STR_SEARCH_WILD},
  87.         {RO_TextPos,TEXTPOS_RIGHT},
  88.         {RO_ChkCenter,TRUE},
  89.         {RO_BoolOn,FALSE},
  90.         {TAG_END,0}},
  91.     search_onlyword_gadget[]={
  92.         {RO_Type,OBJECT_GADGET},
  93.         {RO_GadgetType,GADGET_CHECK},
  94.         {RO_GadgetID,SEARCH_ONLYWORD},
  95.         {RO_Top,4},
  96.         {RO_TopFine,16},
  97.         {RO_TextNum,STR_SEARCH_ONLYWORD},
  98.         {RO_TextPos,TEXTPOS_RIGHT},
  99.         {RO_ChkCenter,TRUE},
  100.         {RO_BoolOn,FALSE},
  101.         {TAG_END,0}},
  102.  
  103.     search_okay_gadget[]={
  104.         {RO_Type,OBJECT_GADGET},
  105.         {RO_GadgetType,GADGET_BOOLEAN},
  106.         {RO_GadgetID,SEARCH_OKAY},
  107.         {RO_Top,5},
  108.         {RO_TopFine,22},
  109.         {RO_Height,1},
  110.         {RO_HeightFine,6},
  111.         {RO_Width,10},
  112.         {RO_TextNum,STR_OKAY},
  113.         {RO_TextPos,TEXTPOS_CENTER},
  114.         {RO_HighRecess,TRUE},
  115.         {TAG_END,0}},
  116.  
  117.     search_cancel_gadget[]={
  118.         {RO_Type,OBJECT_GADGET},
  119.         {RO_GadgetType,GADGET_BOOLEAN},
  120.         {RO_GadgetID,SEARCH_CANCEL},
  121.         {RO_Left,28},
  122.         {RO_LeftFine,38},
  123.         {RO_Top,5},
  124.         {RO_TopFine,22},
  125.         {RO_Height,1},
  126.         {RO_HeightFine,6},
  127.         {RO_Width,10},
  128.         {RO_TextNum,STR_CANCEL},
  129.         {RO_TextPos,TEXTPOS_CENTER},
  130.         {RO_HighRecess,TRUE},
  131.         {TAG_END,0}},
  132.  
  133.     *search_gadgets[]={
  134.         search_text_gadget,
  135.         search_case_gadget,
  136.         search_wild_gadget,
  137.         search_onlyword_gadget,
  138.         search_okay_gadget,
  139.         search_cancel_gadget,
  140.         NULL};
  141.  
  142. get_search_data(buffer,flagptr,window,font)
  143. char *buffer;
  144. int *flagptr;
  145. struct Window *window;
  146. struct TextFont *font;
  147. {
  148.     ULONG class;
  149.     USHORT gadgetid;
  150.     struct Window *swindow;
  151.     struct Gadget *gadlist;
  152.     struct RequesterBase search_req;
  153.     struct StringExtend extend;
  154.     int a,flags;
  155.  
  156.     flags=*flagptr;
  157.  
  158.     search_req.rb_width=38;
  159.     search_req.rb_height=6;
  160.     search_req.rb_widthfine=68;
  161.     search_req.rb_heightfine=40;
  162.     search_req.rb_leftoffset=14;
  163.     search_req.rb_topoffset=8;
  164.  
  165.     search_req.rb_fg=
  166.         (window->UserData)?window->UserData[SEARCH_COL_FG]:screen_pens[config->requestfg].pen;
  167.     search_req.rb_bg=
  168.         (window->UserData)?window->UserData[SEARCH_COL_BG]:screen_pens[config->requestbg].pen;
  169.     search_req.rb_shine=
  170.         (window->UserData)?window->UserData[SEARCH_COL_SHINE]:screen_pens[config->gadgettopcol].pen;
  171.     search_req.rb_shadow=
  172.         (window->UserData)?window->UserData[SEARCH_COL_SHADOW]:screen_pens[config->gadgetbotcol].pen;
  173.  
  174.     search_req.rb_font=font;
  175.     search_req.rb_screen=window->WScreen;
  176.     search_req.rb_extend=&extend;
  177.  
  178.     extend.Font=font;
  179.     extend.Pens[0]=
  180.         (window->UserData)?window->UserData[SEARCH_COL_STRINGFG]:screen_pens[config->stringfgcol].pen;
  181.     extend.Pens[1]=
  182.         (window->UserData)?window->UserData[SEARCH_COL_STRINGBG]:screen_pens[config->stringbgcol].pen;
  183.     extend.ActivePens[0]=
  184.         (window->UserData)?window->UserData[SEARCH_COL_STRINGSELFG]:screen_pens[config->stringselfgcol].pen;
  185.     extend.ActivePens[1]=
  186.         (window->UserData)?window->UserData[SEARCH_COL_STRINGSELBG]:screen_pens[config->stringselbgcol].pen;
  187.     extend.InitialModes=0;
  188.     extend.EditHook=NULL;
  189.     extend.WorkBuffer=NULL;
  190.     for (a=0;a<4;a++) extend.Reserved[a]=0;
  191.  
  192.     search_req.rb_idcmpflags=IDCMP_GADGETUP|IDCMP_MOUSEBUTTONS;
  193.  
  194.     search_req.rb_screenname=NULL;
  195.     search_req.rb_memory=NULL;
  196.     search_req.rb_objects=NULL;
  197.     search_req.rb_privateflags=0;
  198.     search_req.rb_privatedata=NULL;
  199.  
  200.     if (config->generalscreenflags&SCR_GENERAL_REQDRAG) {
  201.         search_req.rb_title=globstring[STR_ENTER_SEARCH_STRING];
  202.         search_req.rb_flags=RBF_BORDERS|RBF_STRINGS;
  203.     }
  204.     else {
  205.         search_req.rb_title=NULL;
  206.         search_req.rb_flags=RBF_STRINGS;
  207.     }
  208.  
  209.     search_req.rb_flags|=RBF_WINDOWCENTER;
  210.     search_req.rb_window=window;
  211.  
  212.     search_req.rb_string_table=globstring;
  213.  
  214.     set_reqobject(search_text_gadget,RO_StringBuf,(ULONG)buffer);
  215.     set_reqobject(search_case_gadget,RO_BoolOn,(flags&SEARCH_NOCASE)?TRUE:FALSE);
  216.     set_reqobject(search_wild_gadget,RO_BoolOn,(flags&SEARCH_WILDCARD)?TRUE:FALSE);
  217.     set_reqobject(search_onlyword_gadget,RO_BoolOn,(flags&SEARCH_ONLYWORDS)?TRUE:FALSE);
  218.  
  219.     if (!(swindow=OpenRequester(&search_req)) ||
  220.         !(gadlist=addreqgadgets(&search_req,search_gadgets,0,NULL))) {
  221.         CloseRequester(&search_req);
  222.         return(0);
  223.     }
  224.     AddRequesterObject(&search_req,search_title);
  225.     RefreshRequesterObject(&search_req,NULL);
  226.  
  227.     ActivateStrGad(gadlist,swindow);
  228.  
  229.     FOREVER {
  230.         while (IMsg=(struct IntuiMessage *)GetMsg(swindow->UserPort)) {
  231.             class=IMsg->Class;
  232.             if (class==IDCMP_GADGETUP)
  233.                 gadgetid=((struct Gadget *) IMsg->IAddress)->GadgetID;
  234.             ReplyMsg((struct Message *) IMsg);
  235.  
  236.             switch (class) {
  237.                 case IDCMP_MOUSEBUTTONS:
  238.                     ActivateStrGad(gadlist,swindow);
  239.                     break;
  240.  
  241.                 case IDCMP_GADGETUP:
  242.                     switch (gadgetid) {
  243.                         case SEARCH_CASE:
  244.                             flags^=SEARCH_NOCASE;
  245.                             ActivateStrGad(gadlist,swindow);
  246.                             break;
  247.                         case SEARCH_WILD:
  248.                             flags^=SEARCH_WILDCARD;
  249.                             ActivateStrGad(gadlist,swindow);
  250.                             break;
  251.                         case SEARCH_ONLYWORD:
  252.                             flags^=SEARCH_ONLYWORDS;
  253.                             ActivateStrGad(gadlist,swindow);
  254.                             break;
  255.  
  256.                         case SEARCH_TEXT:
  257.                         case SEARCH_OKAY:
  258.                         case SEARCH_CANCEL:
  259.                             *flagptr=flags;
  260.                             CloseRequester(&search_req);
  261.                             return((gadgetid!=SEARCH_CANCEL));
  262.                     }
  263.                     break;
  264.             }
  265.         }
  266.         Wait(1<<swindow->UserPort->mp_SigBit);
  267.     }
  268. }
  269.